package com.crm.channel.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crm.channel.mapper.BaseChannelMapper;
import com.crm.channel.domain.BaseChannel;
import com.crm.channel.service.IBaseChannelService;

/**
 * 渠道信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-29
 */
@Service
public class BaseChannelServiceImpl implements IBaseChannelService 
{
    @Autowired
    private BaseChannelMapper baseChannelMapper;

    /**
     * 查询渠道信息
     * 
     * @param id 渠道信息主键
     * @return 渠道信息
     */
    @Override
    public BaseChannel selectBaseChannelById(Long id)
    {
        return baseChannelMapper.selectBaseChannelById(id);
    }

    /**
     * 查询渠道信息列表
     * 
     * @param baseChannel 渠道信息
     * @return 渠道信息
     */
    @Override
    public List<BaseChannel> selectBaseChannelList(BaseChannel baseChannel)
    {
        return baseChannelMapper.selectBaseChannelList(baseChannel);
    }

    /**
     * 新增渠道信息
     * 
     * @param baseChannel 渠道信息
     * @return 结果
     */
    @Override
    public int insertBaseChannel(BaseChannel baseChannel)
    {
        baseChannel.setCreateTime(DateUtils.getNowDate());
        return baseChannelMapper.insertBaseChannel(baseChannel);
    }

    /**
     * 修改渠道信息
     * 
     * @param baseChannel 渠道信息
     * @return 结果
     */
    @Override
    public int updateBaseChannel(BaseChannel baseChannel)
    {
        baseChannel.setUpdateTime(DateUtils.getNowDate());
        return baseChannelMapper.updateBaseChannel(baseChannel);
    }

    /**
     * 批量删除渠道信息
     * 
     * @param ids 需要删除的渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteBaseChannelByIds(Long[] ids)
    {
        return baseChannelMapper.deleteBaseChannelByIds(ids);
    }

    /**
     * 删除渠道信息信息
     * 
     * @param id 渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteBaseChannelById(Long id)
    {
        return baseChannelMapper.deleteBaseChannelById(id);
    }
    /**
     * 根据渠道编号+城市查询渠道配置
     * @param channelSource
     * @param city
     * @return
     */
    @Override
    public BaseChannel getChannelInfo(String channelSource, String city) {
        BaseChannel baseChannel = new BaseChannel();
        baseChannel.setStatus(8L);
        baseChannel.setChannelSource(channelSource);
        baseChannel.setCityLimit(city);

        List<BaseChannel> list = baseChannelMapper.selectBaseChannelList(baseChannel);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
    /**
     * 根据渠道编号+城市查询渠道配置
     * @param channelSource
     * @return
     */
    @Override
    public BaseChannel getChannelInfo(String channelSource) {
        BaseChannel baseChannel = new BaseChannel();
        baseChannel.setStatus(8L);
        baseChannel.setChannelSource(channelSource);

        List<BaseChannel> list = baseChannelMapper.selectBaseChannelList(baseChannel);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
}
